<?php
global $_W, $_GPC;
$settings = $this->module['config'];
if ($settings['switch'] == 0) {
	message('积分商城已关闭！', '', 'error');
}
$request_array = $_GPC;
foreach ($request_array as $key => $val) {
	$unsetkeyarr = array('i', 'do', 'm', 'c');
	if (in_array($key, $unsetkeyarr) || strstr($key, '__')) {
		unset($request_array[$key]);
	}
}
$ret = $this->parseCreditNotify($settings['appkey'], $settings['appsecret'], $request_array);
if (is_array($ret) && $ret['success'] == "true") {
	$order = pdo_fetch("SELECT * FROM " . tablename($this->tableduiba) . " WHERE  uniacid = :uniacid AND orderNum = :orderNum ", array(':uniacid' => $_W['uniacid'], ':orderNum' => $ret['orderNum']));
	if ($order['status'] == 0) {
		$result = pdo_update($this->tableduiba, array('status' => 1, 'endtimestamp' => $request_array['timestamp']), array('id' => $order['id']));
		if (!empty($result)) {
			die('ok');
		}
	} elseif ($order['status'] == 1) {
		die('ok');
	}
} elseif (is_array($ret) && $ret['success'] == "false") {
	$order = pdo_fetch("SELECT * FROM " . tablename($this->tableduiba) . " WHERE  uniacid = :uniacid  AND orderNum = :orderNum ", array(':uniacid' => $_W['uniacid'], ':orderNum' => $ret['orderNum']));
	if ($order['status'] != 2) {
		$result = pdo_update($this->tableduiba, array('status' => 2, 'endtimestamp' => $request_array['timestamp']), array('id' => $order['id']));
		if (!empty($result)) {
			$updatecredit = mc_credit_update($request_array["uid"], 'credit1', abs($request_array["credits"]), array("兑吧", "兑吧兑换失败，退还积分"));
			if (!empty($updatecredit)) {
				die('ok');
			}
		}
	} elseif ($order['status'] == 2) {
		die('ok');
	}
}